package zhizhemodi.tech.short_term_bwork.controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import zhizhemodi.tech.short_term_bwork.entity.PlanAndProgram;
import zhizhemodi.tech.short_term_bwork.service.PlanAndProgramService;
import zhizhemodi.tech.short_term_bwork.tool.CommonResult;

@RestController
@RequestMapping("planAndProgram")
public class PlanAndProgramController {
    
    @Resource
    PlanAndProgramService planAndProgramService;

    @GetMapping("list")
    public CommonResult<?> getPlanAndProgramList(
        @RequestParam("planId") Integer planId
    ) {
        List<PlanAndProgram> re = null;
        try {
            re = planAndProgramService.getPlanAndProgramByPlanId(planId);
        } catch (Exception e) {
            CommonResult.failed(e.getMessage());
        }
        return CommonResult.success(re);
    }

    @PostMapping("add")
    public CommonResult<?> addPlanAndProgramList(
        @RequestBody List<PlanAndProgram> planAndPrograms
    ) {
        try {
            planAndProgramService.addPlanAndProgramList(planAndPrograms);
        } catch (Exception e) {
            return CommonResult.failed(e.getMessage());
        }
        return CommonResult.success("添加成功");
    }
}
